<template>
  <tr>
    <td>{{lists.id}}</td>
    <td>{{lists.name}}</td>
    <td>{{momt}}</td>
    <td>
      <button :disabled = "lit.length === 1 ? true : false" @click="delClick(lists.id)">删除</button>
      <button @click="edit(lists.id)">编辑</button>
    </td>
  </tr>
</template>

<script>
import moment from 'moment'
import axios from 'axios'
axios.defaults.baseURL = 'http://liufusong.top:4000/'
export default {
  data () {
    return {
      momt: moment(this.lists.date).format('YYYY-MM-DD')
    }
  },
  props: {
    lists: {
      type: Object,
      required: true
    },
    lit: {
      type: Array,
      required: true
    }
  },
  created () {

  },

  methods: {
    async delClick (id) {
      try {
        const res = await axios({
          url: 'books/' + id,
          method: 'DELETE'
        })
        if (res.data.status === 200) {
          console.log('请求成功')
        }
        console.log(res)
      } catch (err) {
        alert(err)
      }
      this.$emit('delts')
    },
    async edit (ids) {
      try {
        const res = await axios({
          url: 'books/' + ids,
          method: 'GET'
        })
        this.$emit('changeCheck', res.data)
      } catch (err) {
        alert(err, '编辑请求出错')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
